package com.zb.zeus.common.core.web.filter;

import org.slf4j.MDC;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author fujianjian
 * @date 2022/5/9 15:52
 **/
public class RequestNumFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String traceId = MDC.get("traceId");
        String spanId = MDC.get("spanId");
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.addHeader("traceId", traceId);
        response.addHeader("spanId", spanId);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
